package com.markus.code.剑指offer;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/2 17:32
 * todo: 把数组排成最小的数
 */
public class MinNumber {
    public String minNumber(int[] nums) {
        if (nums == null || nums.length == 0){
            return "";
        }
        String []str = new String[nums.length];
        for (int i=0;i<str.length;i++){
            str[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(str, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (o1+o2).compareTo(o2+o1);
            }
        });
        StringBuffer sb = new StringBuffer();
        for (int i=0;i<str.length;i++){
            sb.append(str[i]);
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        int nums[] = {10,2};
        MinNumber demo = new MinNumber();
        System.out.println(demo.minNumber(nums));
    }
}
